<?php
namespace core;
date_default_timezone_set('PRC'); //设置时区

class mrcln{

	public static $classMap = array();
	public $assign;  //定义一个存放试图变量的变量

	static public function run(){
		
		#加载日志类
		\core\lib\log::init();

		#加载路由类
		$routes = new \core\lib\routes();

		#加载控制器的方法
		#参考routes.php
		$controllerClass = $routes->controller;
		$action = $routes->action;
		$controllerfile = APP.'/controller/'.$controllerClass.'Controller.php';
		$ctrlfile = '\\'.MODULE.'\controller\\'.$controllerClass.'Controller';
		if (is_file($controllerfile)) {
			include $controllerfile;
			$controller = new $ctrlfile;
			$controller->$action();
			\core\lib\log::log('controller:'.$controllerClass.'   '.'action:'.$action);
		}else{
			throw new \Exception("找不到控制器".$controllerClass);// \Exception调用系统类注意加斜杠，
			
		}
	}

	#自动加载类库
	static public function load($class)
	{
		
		//new \core\routes();
		//$class = '\core\routes';
		//MRCLN.'/core/routes.php';
		//需要将路径的反斜杠\替换成斜杠/实现加载类库
		if (isset($classMap[$class])) {
			return true;
		}else{
			$class = str_replace('\\', '/', $class);
			$file = MRCLN.'/'.$class.'.php';
			if (is_file($file) ) {
				include $file;
				self::$classMap[$class] = $class;
			}else{
				return false;
			}
		}
		
	}
	#变量输出配置
	public function assign($name,$value)
	{
		$this->assign[$name] = $value; 
		
	}
	#试图输出配置
	public function display($file)
	{
		//var_dump($this->assign);
		$file = APP.'/view/'.$file.'.html';
		if (is_file($file)) {
			
			extract($this->assign); //拆分数组，讲值直接赋给变量data
			include $file;
		}
	}
}